<template>
  <!--价格管理列表-->
  <div v-if="editDialogVisible6">
    <el-form  :inline="true"  :model="dataFormPrice"  :rules="dataFormRulesPrice"  ref="dataForm"  label-width="115px"  class="demo-dataForm">
      <p style="padding:0 0 20px 0;font-size:20px" ><strong>标准价格</strong></p>
      <!--第一行-->
      <el-row id="rowMargin">
       <!-- 左边栏
         <el-col :span="6" >
          <el-form-item label="零售价：" prop="salePriceWithTax">
              <el-input v-model="dataFormPrice.salePriceWithTax" :disabled=" dataFormPrice.isAudit != 0" oninput="value = value.match(/^\d*(\.?\d{0,2})/g)[0]" placeholder="零售价" clearable></el-input>
              <el-tooltip style="font-size: 20px;" effect="light" :enterable="false" placement="right" v-if="dataFormPrice.isAudit != 0">
                <div slot="content" style="min-width: 200px; min-height: 80px;">
                  <p>价格正在审核中......</p>
                  <p>发起人: {{dataFormPrice.creatorName}}</p>
                  <p>修改时间: {{dataFormPrice.createTime}}</p>
                </div>
                <i class="el-icon-question"/>
              </el-tooltip>
          </el-form-item>
        </el-col>
        中间栏
        <el-col :span="6">
          <el-form-item label="市场价：" prop="marketPrice">
            <el-input v-model="dataFormPrice.marketPrice" oninput="value = value.match(/^\d*(\.?\d{0,2})/g)[0]" clearable placeholder="市场价"></el-input>
          </el-form-item>
        </el-col>
        右边栏
         <el-col :span="6">
          <el-form-item label="采购价：" prop="purchasePriceWithTax">
            <el-input v-model="dataFormPrice.purchasePriceWithTax" oninput="value = value.match(/^\d*(\.?\d{0,2})/g)[0]" clearable placeholder="采购价"></el-input>
          </el-form-item>
        </el-col>
      </el-row> 
      <el-row id="rowMargin">
         <!-- 左边栏  -->
         <el-col :span="7" >
          <el-form-item label="合同协议扣点" prop="saleTaxRate">
            <el-input v-model="dataFormPrice.saleTaxRate" oninput="value = value.match(/^\d*(\.?\d{0,2})/g)[0]"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

    <el-row id="rowMargin" :gutter="30" >
        <!-- 左边栏 -->
        <el-col :span="7">
          <el-form-item label="市场价" prop="marketPrice">
             <el-input v-model="dataFormPrice.marketPrice" oninput="value = value.match(/^\d*(\.?\d{0,2})/g)[0]"></el-input>
          </el-form-item>
        </el-col>
        <!-- 中间栏 -->
        <el-col :span="7">
          <el-form-item label="零售价" prop="salePriceWithTax">
              <el-input v-model="dataFormPrice.salePriceWithTax" @change="changePoints"  oninput="value = value.match(/^\d*(\.?\d{0,2})/g)[0]"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="7">
          <el-form-item label="结算" prop="salePriceWithoutTax">
             <el-input v-model="dataFormPrice.salePriceWithoutTax" @change="changePoints"  ninput="value = value.match(/^\d*(\.?\d{0,2})/g)[0]"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="7">
          <el-form-item label="平台服务费" prop="platformServiceFee">
             <el-input v-model="dataFormPrice.platformServiceFee" oninput="value = value.match(/^\d*(\.?\d{0,2})/g)[0]"></el-input>
          </el-form-item>
        </el-col>
      <el-col :span="7">
        <el-form-item label="总库存(普通商品使用)" prop="totalStock">
          <el-input v-model="dataFormPrice.totalStock" oninput="value = value.match(/^\d*(\.?\d{0,2})/g)[0]"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="7">
        <el-form-item label="可用库存(普通商品使用)" prop="availableStock">
          <el-input v-model="dataFormPrice.availableStock" oninput="value = value.match(/^\d*(\.?\d{0,2})/g)[0]"></el-input>
        </el-form-item>
      </el-col>
      </el-row>
      <!-- 第二行
      <el-row id="secondRow">
        左边栏
        <el-col :span="6">
          <el-form-item label="进项税码：" prop="purchaseTaxRate">
            <el-select v-model="dataFormPrice.purchaseTaxRate" clearable>
              <el-option v-for="item in purchaseTaxRate" :key="item.id" :label="item.name" :value="item.id" ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        中间栏
        <el-col :span="6">
          <el-form-item label="销项税码：" prop="saleTaxRate">
            <el-select v-model="dataFormPrice.saleTaxRate" clearable>
              <el-option
                v-for="item in saleTaxRate"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>-->
  <el-row id="rowMargin" :gutter="30" >
        <!-- 左边栏 -->
        <el-col :span="7" >
          <el-form-item label="测算扣点" prop="points">
             <el-input v-model="dataFormPrice.points" oninput="value = value.match(/^\d*(\.?\d{0,2})/g)[0]"></el-input>
          </el-form-item>
        </el-col>
         <el-col :span="10">
          <span style="color:red">说明：测算扣点=（零售价-结算价）/零售价*100% </span>
        </el-col>
      </el-row>

      <el-row id="footerButton">
        <el-col :span="6" :offset="10">
          <el-form-item>
            <el-button
              :size="size"
              type="primary"
              @click.native="submitFormPrice"
              :loading="editLoading"
            >{{ $t("action.submit") }}
            </el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import CyTable from "@/views/Core/CyTable";
import KtButton from "@/views/Core/KtButton";
import { format, formatDate } from "@/utils/datetime";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
import { quillEditor } from "vue-quill-editor"; 
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";

export default {
  components: {
    KtButton,
    CyTable,
    TableColumnFilterDialog,
    quillEditor
  },
  data() {
    return {
      size: "small",
      editDialogVisible6: false,
      dataFormPrice: {
        salePriceWithTax: "",
        marketPrice: "",
        purchasePriceWithTax: "",
        saleTaxRateId: "",
        purchaseTaxRateId: "",
        id: 0,
        isAudit: 0,
        createTime: "",
        creatorName: "",
        availableStock: 0,
        totalStock: 0,
      },
      dataFormRulesPrice: {
        salePriceWithTax: [
          { required: true, message: "请输入零售价", trigger: "blur" }
        ],
        salePriceWithoutTax: [
          { required: true, message: "请输入结算", trigger: "blur" }
        ],
        platformServiceFee: [
          { required: true, message: "请输入平台服务费", trigger: "blur" }
        ]
      },
      saleTaxRate: [
        {
          id: 0.15,
          name: 0.15
        }
      ],
      purchaseTaxRate: [
        {
          id: 0.1,
          name: 0.1
        },
        {
          id: 0.17,
          name: 0.17
        }
      ],
      editLoading: false,
      productId: 0
    };
  },
  mounted() {},
  methods: {
    init(param) {
      this.editDialogVisible6 = param.flag;
      this.productId = param.productId;
      if (param.flag) {
        this.queryProductPrice(param);
      }
      if(param.isUpdate){
        this.submitFormPrice();
      }
    },
    queryProductPrice(param) {
      let this_ = this;
      this.utils.request.queryProductPrice(param, function(data) {
        if (data.data != null) {
          this_.dataFormPrice = data.data;
        }
      });
    },
    changePoints(){
        if(this.dataFormPrice.salePriceWithTax && this.dataFormPrice.salePriceWithoutTax){
          this.dataFormPrice.points=((this.dataFormPrice.salePriceWithTax-this.dataFormPrice.salePriceWithoutTax)/this.dataFormPrice.salePriceWithTax*100/100).toFixed(2);
        }
    },
    submitFormPrice: function(product) {
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          this.$confirm("确认提交吗？", "提示", {}).then(() => {
            let this_ = this;
            let param = Object.assign({}, this.dataFormPrice);
            param.productId = this_.productId;
            this.utils.request.addOrUpdateProductPrice(param, function(res) {
              if (res.code == "0000") {
                this_.dataFormPrice.id = res.data.id;
                this_.$message({ message: "操作成功", type: "success" });
              } else {
                this_.$message({
                  message: "操作失败, " + res.msg,
                  type: "error"
                });
              }
            });
          });
        } else {
          return false;
        }
      });
    }
  }
};
</script>

<style scoped lang='scss'>
/*  .el-col {
  margin-bottom: 20px !important;
}  */
</style>
